home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / languages / cleo.lzh / Cleo / source / libs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-24  |  4.5 KB  |  162 lines

  1. /***************************************************************************
  2. *   Ce fichier, ainsi que tous les  modules  l'accompagnant, peut et  doit *
  3. * etre  copié GRATUITEMENT à la seule condition expresse de conserver      *
  4. * l'INTEGRALITE  du  Code Source, de  la documentation, et  des fichiers   *
  5. * annexes du package. Ce logiciel est Shareware, veuilez envoyer 100 FF à  *
  6. * l'auteur pour recevoir regulièrement les nouvelles versions.             *
  7. * Toute modification est INTERDITE sans l'autorisation écrite de l'auteur. *
  8. *            Tous droits réservés à M. DIALLO Barrou, Juillet 1992.        *
  9. ***************************************************************************/
  10.  
  11.         /**          Module de gestions des fonction externes   **/
  12.  
  13. #ifdef msdos
  14.         #include "include\\cleobis.h"
  15.         #include "include\\libs.h"
  16. #else
  17.         #include "include/cleobis.h"
  18.         #include "include/libs.h"
  19. #endif
  20.  
  21. extern void TraitErreur (char type, int num, int lig, int col);
  22. extern int curlg;
  23. extern int curcol;
  24. extern char curtoken[];
  25. extern CONST *symb;
  26. extern CONST *cursymb;
  27. extern VAR *var;
  28. extern VAR *curvar;
  29. extern int NbVar;
  30. extern MY_TYPESID curtokentype;
  31. extern MY_TYPESID lasttokentype;
  32. extern MY_TYPESID facttype;
  33. extern MY_CONST curconst;
  34. extern Entete head;
  35. extern int curtokenid;
  36. extern int lasttokenid;
  37. extern int curadr;
  38. extern long AdressSize;
  39. extern int *Adress;
  40. extern int pcpc;
  41. extern FIELDSTRUCT Field[];
  42. extern FCTLIB *extfct, *curextfct, *curlibfct;
  43.  
  44. void PrintExtFct(FCTLIB *fonc)
  45. {
  46.     int m;
  47.     printf("\t\t\tnom:\t%s\n", fonc->nom);
  48.     printf("\t\t\tid:\t%d\n", fonc->id);
  49.     printf("\t\t\tnbarg:\t%d\n", fonc->nbarg);
  50.     for (m=0; m< fonc->nbarg; printf("\t\t\t\targ type No%d = %d\n", m,fonc->type[m]), m++);
  51.     printf("\t\t\tretype:\t%d\n", fonc->retype);
  52. }
  53.  
  54. void AnalyseExtern(void)
  55. {
  56.     int nbpara= curlibfct->nbarg;
  57.     int n=1;
  58.  
  59. /*    PrintExtFct(curlibfct); */
  60.  
  61.     Lexical();
  62.     if ( *curtoken != '(' )
  63.         TraitErreur (TEXTERROR, NOPO, curlg, curcol);
  64.     do {
  65.         Lexical();
  66.         Simple_Exp();
  67.        } while (n++ <= nbpara && *curtoken == ',');
  68.  
  69.     if (n-1 != nbpara)
  70.         TraitErreur ( TEXTERROR, NBPARA, curlg, curcol);
  71.     if ( *curtoken != ')' )
  72.         TraitErreur ( TEXTERROR, NOPF, curlg, curcol);
  73.     else
  74.         Lexical();
  75.  
  76.     Code(PUSHVAL,curlibfct->id);
  77.     Code(LIBRARY, curlibfct->node);
  78. }
  79.  
  80. void InsExternFct(FCTLIB *ele)
  81. {
  82.     if (!extfct)
  83.         {
  84.             extfct = (FCTLIB *) ele;
  85.             curextfct= extfct;
  86.         }
  87.     else
  88.         {
  89.             curextfct->next = (FCTLIB *) ele;
  90.             curextfct = curextfct->next;
  91.         }
  92.     curextfct->next = NULL;
  93.     head.nbrefctlib++;              /* 1 fct library en plus */
  94. }
  95.  
  96. void ReadLib(fic)
  97.     FILE *fic;
  98. {
  99.     LIBHEAD header;
  100.     FCTLIB *fonc=NULL;
  101.     int n,namesz;
  102.     char nom[MAXSTRING];
  103.  
  104.     fread(&header, sizeof(LIBHEAD), 1, fic);
  105. #ifdef verbose
  106.     printf("\t\tLibrary %s avec %d declarations de fonctions\n", header.nom, header.nbfct);
  107.     printf("\t\t\tLibrary Node: %d\n", header.node);
  108. #endif
  109.     for (n=0; n< header.nbfct; n++)
  110.         {
  111.         fonc = (FCTLIB *)calloc(sizeof(FCTLIB),1);
  112.         fread(&namesz, sizeof(int),1, fic);      /* taille nom */
  113.         fgets(nom, namesz+1, fic);
  114.         fonc->nom = (char *)strdup(nom);           /* nom */
  115.         fread(&fonc->id, sizeof(int),1, fic);      /* id */
  116.  
  117.         fread(&fonc->retype, sizeof(int),1, fic);  /* typeret */
  118.         fread(&fonc->nbarg,sizeof(int),1, fic);    /* Nbre d'args */
  119.         fonc->type =(int *)calloc(sizeof(int)*fonc->nbarg,1);
  120.         fread(fonc->type,sizeof(int)*fonc->nbarg ,1, fic);   /*tab de type */
  121.         fonc->node = header.node;
  122.         InsExternFct(fonc);
  123. #ifdef verbose
  124.     PrintExtFct(fonc);
  125. #endif
  126.         }
  127. }
  128.  
  129. void inclib_fct(text)
  130.     BOOL text;
  131. {
  132.     char incnom[MAXSTRING];
  133.     BOOL fin=FALSE;
  134.     FILE *fic;
  135.  
  136.     Lexical();
  137.     if (curtokenid != pluspetit_b)
  138.         TraitErreur ( TEXTERROR, NOPPQ, curlg, curcol);
  139.     Lexical();
  140.     strcpy(incnom, curtoken);
  141.     Lexical();
  142.     while (!fin)
  143.         {
  144.             if (curtokenid != plusgrand_b)
  145.                 {
  146.                 strcat(incnom,curtoken);
  147.                 Lexical();
  148.                 }
  149.             else fin =TRUE;
  150.         }
  151.     if(text)                 /* Si inclib dans le prg, alors no virg */
  152.         *curtoken= ';' ;
  153.     else
  154.         Lexical();          /* Avant Program, Begin */
  155.  
  156.     if (!(fic=fopen(incnom,"rb")))
  157.         TraitErreur ( TEXTERROR, CANTOPENLIB, curlg, curcol);
  158.  
  159.     ReadLib(fic);
  160.     fclose(fic);
  161. }
  162.